import User.User;
import User.AdminUser;
import User.NormalUser;
import User.factor.AdminUserFactory;
import User.factor.IUserFactory;
import User.factor.NormalUserFactory;
import User.ProxyUser;

import java.util.Scanner;

public class LibrarySystem {
    public static void main(String[] args) {
        //图书管理员系统入口；

        //工厂模式；
        IUserFactory adminUserFactory = new AdminUserFactory();
        User adminUser = adminUserFactory.createUser("刘备", 1);
        IUserFactory normalUserFactory = new NormalUserFactory();
        User normal1 = normalUserFactory.createUser("关羽", 2);
        User normal2 = normalUserFactory.createUser("张飞", 3);

        //-引⼊代理模式控制对象权限
        ProxyUser proxyUserAdmin = new ProxyUser(adminUser);
        ProxyUser proxyUserNormalG = new ProxyUser(normal1);
        ProxyUser proxyUserNormalZ = new ProxyUser(normal2);
        ProxyUser currentUser = selectProxyRole(proxyUserAdmin, proxyUserNormalG, proxyUserNormalZ);
        while(true){
            int choice = currentUser.getRealuser().display();
            currentUser.handleOperation(choice);
        }

    }
        public static ProxyUser  selectProxyRole (ProxyUser proxyUserAdmin,
                ProxyUser proxyUserNormalG,
                ProxyUser proxyUserNormalZ){
            System.out.println("选择角色进行登录：");
            System.out.println("1.管理员\n2.普通用户(关羽)\n3.普通用户(张飞)\n4.退出系统");
            ProxyUser currentUser = null;
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    currentUser = proxyUserAdmin;
                    break;
                case 2:
                    currentUser = proxyUserNormalG;
                    break;
                case 3:
                    currentUser = proxyUserNormalZ;
                    break;
                case 4:
                    System.out.println("退出系统");
                    System.exit(0);
                default:
                    break;
            }
            return currentUser;
        }
    }
